package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.db.domain.MarketUserExample;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import com.cskaoyan.market.util.MybatisUtils;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdminUserServiceImpl implements AdminUserService{
    @Override
    public List<MarketUser> list(String page, String limit, String sort, String order, String username, String mobile) {
        SqlSession session= MybatisUtils.getSession();
        MarketUserMapper marketUserMapper=session.getMapper(MarketUserMapper.class);
        MarketUserExample marketUserExample =new MarketUserExample();
        MarketUserExample.Criteria criteria=marketUserExample.createCriteria();
        if(!StringUtils.isEmpty(username)){
            criteria.andUsernameLike("%"+ username +"%");
        }
        if(!StringUtils.isEmpty(mobile)){
            criteria.andMobileLike("%" + mobile + "%");
        }
        marketUserExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
        List<MarketUser> marketUsers = marketUserMapper.selectByExample(marketUserExample);
        session.close();
        return marketUsers;
    }
}
